#include "Game.h"
#include "SpriteFont.h"
#include <string>
#include "Quad.h"

using std::string;
using namespace DirectX;
Game::Game(void)
{
	m_D3D = 0;
}


Game::~Game(void)
{
}


bool Game::Initialize(int screenWidth, int screenHeight, HWND hwnd, InputManager* input)
{

	bool result;


	// Create the Direct3D object.
	m_D3D = new GraphicsDevice;
	if(!m_D3D)
	{
		return false;
	}

	// Initialize the Direct3D object.
	result = m_D3D->Initialize(screenWidth, screenHeight, VSYNC_ENABLED, hwnd, FULL_SCREEN, SCREEN_DEPTH, SCREEN_NEAR);
	if(!result)
	{
		MessageBox(hwnd, L"Could not initialize Direct3D", L"Error", MB_OK);
		return false;
	}

	m_spriteBatch.reset( new SpriteBatch( m_D3D->GetDeviceContext() ) );
	m_sFont.reset( new SpriteFont( m_D3D->GetDevice(), L"Resources\\italic.spritefont" ) );

	m_inputManager = input;
	m_camera = new DebugCamera();
	m_camera->Initialize( XMVectorZero(), XMVectorZero() );

	m_quad = new Quad(this);
	m_quad->Initialize();
	return true;
}


void Game::Shutdown()
{

	if(m_D3D)
	{
		m_D3D->Shutdown();
		delete m_D3D;
		m_D3D = 0;
	}

	return;
}

bool Game::Update(GameTime gameTime)
{
	m_camera->Update(gameTime);
	float dT = gameTime.DeltaTime();
	return true;
}


bool Game::Draw(GameTime gameTime)
{

	// Clear the buffers to begin the scene.
	m_D3D->BeginScene(Colors::CornflowerBlue);

	//m_spriteBatch->Begin( SpriteSortMode_Deferred );
	//m_sFont->DrawString( m_spriteBatch.get(), L"Hej", XMVectorSet( 10, 10,10,1 ), Colors::Yellow,0.0f, g_XMZero, 0.4f );

	//m_spriteBatch->End();
	m_quad->Draw();
	// Present the rendered scene to the screen.
	m_D3D->EndScene();

	return true;
}
